<?php
/**
 * 平台管理
 * lixinguo
 * 2017-7-10
 */
namespace Admin\Controller;
use Common\Controller\AdminbaseController;
class CompanyController extends AdminbaseController
{
    //简介
    public function profile(){
        if(IS_POST){
            $desc = $_POST['desc'];
//            if (!$_FILES['b_img']['error']){
//                //上传图片
//                $upload = new \Think\Upload();// 实例化上传类
//                $upload->maxSize   =     11048576 ;// 设置附件上传大小
//                $upload->exts      =     array('jpg','png','jpeg','gif');// 设置附件上传类型
//                $upload->rootPath  =     './public/images/'; // 设置附件上传根目录
//                $upload->savePath  =     ''; // 设置附件上传（子）目录
//                // 上传文件
//                $info   =   $upload->upload();
//                // var_dump($info);
//                if(!$info) {// 上传错误提示错误信息
//                    $this->error($upload->getError());
//                }else{// 上传成功 获取上传文件信息
//                    $pic = "/public/images/".$info['b_img']['savepath'].$info['b_img']['savename'];
//                    $ad['b_img'] = $pic;
//                    $ad['desc'] = $desc;
//                    $save = M("Company")->where(array('id'=>1))->save($ad);
//                    if($save){
//                        $this->success("上传成功！",U("Company/profile"));
//                    }else{
//                        $this->error("上传失败！");
//                    }
//                }
//            }else{
                $ad['desc'] = $desc;
//                dump($ad);die;
                $save = M("Company")->where(array('id'=>1))->save($ad);
                if($save!==false){
                    $this->success("保存成功！",U("Company/profile"));
                }else{
                    $this->error("网络错误！");
                }
//            }
        }else{
            $info = M('company')->where(array('id'=>1))->find();
            $this->assign('info',$info);
            $this->display();
        }
    }

    //常见问题
    public function problem(){
        $info = M("problem")->select();
        $this->assign('info',$info);
        $this->display();
    }
    public function add_problem(){
        if(IS_POST){
            $data['title'] = $_POST['title'];
            $data['content'] = $_POST['content'];
            if($data==''){
                $this->error('所填参数不能为空');
            }
            $info = M("problem")->add($data);
            if($info!==false){
                $this->success('添加成功',U('Company/problem'));
            }else{
                $this->error('网络错误！');
            }
        }else{
            $this->display();
        }
    }
    public function detail_problem(){
        $id = I("get.id",0,'intval');
        $info = M('problem')->where(array('id'=>$id))->find();
        $this->assign('info',$info);
        $this->display();
    }
    public function edit_problem(){
        $id = I('get.id',0,'intval');
        if(IS_POST){
            $data['title'] = $_POST['title'];
            $data['content'] = $_POST['content'];
            $info = M('problem')->where(array('id'=>$id))->save($data);
            if($info!==false){
                $this->success('保存成功',U("Company/problem"));
            }else{
                $this->error('网络错误');
            }
        }else{
            $info = M("problem")->where(array('id'=>$id))->find();
            $this->assign('info',$info);
            $this->display();
        }

    }

    public function del_problem(){
        $id = I('get.id',0,'intval');
        $info = M('problem')->where(array('id'=>$id))->delete();
        if($info!==false){
            $this->success('删除成功',U('Company/problem'));
        }else{
            $this->error('网络错误');
        }
    }

    //客服中心
    public function service(){
        if(IS_POST){
            $service = $_POST['service'];
            $info = M('company')->where('id =1')->save(array('service'=>$service));
            if($info!==false){
                $this->success('保存成功',U('Company/service'));
            }else{
                $this->error('保存失败');
            }
        }else{
            $info = M("company")->where('id=1')->find();
            $this->assign('info',$info);
            $this->display();
        }
    }

    //加盟细则
    public function rules(){
        if(IS_POST){
            $rules = $_POST['rules'];
            $info = M('company')->where('id =1')->save(array('rules'=>$rules));
            if($info!==false){
                $this->success('保存成功',U('Company/rules'));
            }else{
                $this->error('保存失败');
            }
        }else{
            $info = M("company")->where('id=1')->find();
            $this->assign('info',$info);
            $this->display();
        }
    }
    //客户留言列表
    public function service_list(){
        $info = M("message")->select();
        $this->assign('info',$info);
        $this->display();
    }
    public function edit_list(){
        if(IS_POST){
            $user_id = I('post.id');
            $data['user_name'] = I('post.user_name');
            $data['phone'] = I('post.phone');
            $data['content'] = I('post.content');
            $info = M('message')->where(array('id'=>$user_id))->save($data);
            if($info!==false){
                $this->success('保存成功',U('Company/service_list'));
            }else{
                $this->error('网络错误');
            }
        }else{
            $id = I("get.id",0,'intval');
            $info = M("message")->where(array('id'=>$id))->find();
            $this->assign('info',$info);
            $this->display();
        }

    }
    public function del_list(){
        $id = I('get.id',0,'intval');
        $info = M('message')->where(array('id'=>$id))->delete();
        if($info!==false){
            $this->success('删除成功',U('company/service_list'));
        }else{
            $this->error('网络错误');
        }
    }



















}